package com.byzoro.utils;

import lombok.Data;

@Data
public class JsonResult {
    private int code;
    private String message;
    private Object data;
    private int count;

    @Override
    public String toString() {
        return "{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                ", count=" + count +
                '}';
    }

    public static JsonResult list (String message,Object data, int count) {
        JsonResult JsonResult = new JsonResult();
        JsonResult.setCode(RestfulCode.SUCCESS);
        JsonResult.setMessage(message);
        JsonResult.setCount(count);
        JsonResult.setData(data);
        return JsonResult;
    }

    public static JsonResult success (String message) {
        JsonResult JsonResult = new JsonResult();
        JsonResult.setCode(RestfulCode.SUCCESS);
        JsonResult.setMessage(message);
        return JsonResult;
    }

    public static JsonResult success (String message, Object data) {
        JsonResult JsonResult = new JsonResult();
        JsonResult.setCode(RestfulCode.SUCCESS);
        JsonResult.setMessage(message);
        JsonResult.data = data;
        return JsonResult;
    }

    public static JsonResult fail (String message) {
        JsonResult JsonResult = new JsonResult();
        JsonResult.setCode(RestfulCode.FAIL);
        JsonResult.setMessage(message);
        return JsonResult;
    }

    public static JsonResult fail (int code, String message) {
        JsonResult JsonResult = new JsonResult();
        JsonResult.setCode(code);
        JsonResult.setMessage(message);
        return JsonResult;
    }

}
